/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.muni.fi.veles.polyline;

import com.google.common.collect.Lists;
import cz.muni.fi.veles.AbstractLocation;
import cz.muni.fi.veles.MapServer;
import cz.muni.fi.veles.MapUtils;
import cz.muni.fi.veles.maps.AbstractMap;
import cz.muni.fi.veles.maps.GoogleMap;
import java.util.ArrayList;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;

/**
 * Abstract polyline class
 * @author Jan Ferko
 */
@JsfComponent(
    family=AbstractPolyline.COMPONENT_FAMILY,
    type=AbstractPolyline.COMPONENT_TYPE,
    renderer=@JsfRenderer(family=AbstractPolyline.COMPONENT_FAMILY, type="cz.muni.fi.veles.PolylineRenderer")
)
public abstract class AbstractPolyline extends UIComponentBase{
    public static final String COMPONENT_TYPE = "cz.muni.fi.veles.Polyline";
    public static final String COMPONENT_FAMILY = "cz.muni.fi.veles";

    /**
     * Default value: #FF0000
     * @return stroke color of polyline
     */
    @Attribute(defaultValue="#FF0000")
    public abstract String getStrokeColor();

    /**
     * Default value: 1.0
     * Possible values from 0 to 1.0
     * @return stroke opacity of polyline
     */
    @Attribute(defaultValue="1.0")
    public abstract Double getStrokeOpacity();

    /**
     * Default value: 4
     * 
     * @return width of stroke of polyline
     */
    @Attribute(defaultValue="4")
    public abstract Integer getStrokeWidth();

    /**
     * 
     * @return used map server
     */
    public MapServer resolveMapServer(){
        return MapUtils.resolveMapServer(this);
    }

    /**
     * Path of polyline
     * @return list of abstract locations, which represents path of polyline
     */
    public List<AbstractLocation> getPath(){
        List<AbstractLocation> path = Lists.newArrayList();
        for(UIComponent component: this.getChildren()){
            if(component instanceof AbstractLocation){
                path.add((AbstractLocation) component);
            }
        }
        return path;
    }
}
